<?php
/**
 * Clean up quotes
 */  
if (get_magic_quotes_gpc()) {
    function magicQuotes_awStripslashes(&$value, $key) {$value = stripslashes($value);}
    $gpc = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST);
    array_walk_recursive($gpc, 'magicQuotes_awStripslashes');
}

// Initial Log
myLog(3,$_REQUEST);
myLog(4,$_SERVER);



/**
 * Log 
 * 
 * myLog(3,"este es un mensaje");
 *   
 * 
 * @params $pLevel int Level of log 1-critical, 2-warning, 3-info,  
 * @params $pValue Mixed Value to log  
 */ 
function myLog($pLevel,$pValue){
    if( $pLevel <= APP_DEBUG_LEVEL){
    	$pValue = print_r($pValue,true);
    	$time = time();
    	$PHPSESSID = $_REQUEST['PHPSESSID'];
    	$APP_DEBUG_TOKEN = APP_DEBUG_TOKEN;
    	$line = str_pad($input, 80,'-');
        error_log("\n{$line}\n[{$time}]::{$PHPSESSID}::{$APP_DEBUG_TOKEN}\n{$line}\n{$pValue}", 3, APP_LOG);    
    }
}


function getPermissions(){
    $permissions = unserialize(file_get_contents(DATA_DIR.'fb-list-permissions.serialize'));
    sort($permissions);
    return $permissions;
}


function saveRequest(){
    $params = array(
            'appId'  => FB_APP_ID,
            'secret' => FB_APP_SECRET,
            'cookie' => true,
        );
    $facebook_toolbox = new FacebookToolbox($params);
    $facebook_toolbox->getAppAccessToken();   
    $request = $facebook_toolbox->getRequests();
    echo "<pre>".print_r($_REQUEST,true)."</pre>";
    echo "<pre>".print_r($request,true)."</pre>";exit;
}

/*

Array
(
    [request_id] => 403441299682813
    [data_signed] => Array
        (
            [algorithm] => HMAC-SHA256
            [expires] => 1335594008
            [issued_at] => 1330410008
            [oauth_token] => AAAFnefMXwWcBAMIKEzDZCABYPnNZCQqIKZCohWSGwQErOWWAdFV8g3CzCc3ZBMNQcZB5D89efGuid5en0tFpuqcbZBWW2YjFn8Rgz07tNIbAZDZD
            [user] => Array
                (
                    [country] => ar
                    [locale] => es_LA
                    [age] => Array
                        (
                            [min] => 21
                        )

                )

            [user_id] => 100003508495386
        )

)

*/